<?php
/**
 * @link https://www.kancloud.cn/cleverstone/ymb2
 * @copyright Copyright (c) 2020 Yii Manager Software LLC
 */

use builder\helper\H5;
use yii\helpers\Json;

/** @var \yii\web\View $this */
/* @var string $id 当前树表格组件ID */
/* @var array $ttRowOperation 行操作项 */
/* @var array $ttToolbarCustom 自定义头部工具栏 ['left' => [...], 'right' => [...]] */
/* @var array $ttToolbarFilter 树表格筛选 */
/* @var array $ttToolbarTab 工具选项卡 */
/** @var array $rootLayout 根布局 */
/** @var array $extraDataTpl 额外数据展示模板 */
?>

<div id="__YM2_BUILDER_ID__<?= $id ?>" class="pt-3 card border-0 <?= $rootLayout['class'] ?>" ng-controller="ym2.ctrl.<?= $id ?>" style="<?= $rootLayout['style'] ?>"<?= $rootLayout['attribute'] ?>>
    <!--筛选模板 start -->
<?php if (!empty($ttToolbarFilter)): ?>
    <div class="card-header bg-white border-bottom-0" ng-show="ym2TreeTableFilterShow_<?= $id ?>">
<?= $this->renderPhpFile(__DIR__ . '/tpl/filter.tpl.php', ['ttToolbarFilter' => $ttToolbarFilter, 'builderID' => $id]) ?>
    </div>
<?php endif; ?>
    <!--筛选模板 end -->

    <div class="card-body pt-0">
        <!--树表格模板 start -->
        <?= /* @var \builder\tree_table\TreeTableBuilder $this->context */ $this->context->beginTreeTable() ?>

        <!--选项卡筛选-->
<?php if (!empty($ttToolbarTab)): ?>
        <div class="layui-tabs layui-tabs-brief only-title">
            <ul class="layui-tabs-header m-0">
                <?php foreach ($ttToolbarTab as $key => $item): ?>
                <li class="<?= !empty($item['defaultChecked']) ? 'layui-this' : null ?>" ng-click="triggerTab(<?= H5::encode(Json::encode($item['params'])) ?>)">
                    <?= !empty($item['icon']) ? '<i class="' . $item['icon'] . '"></i>' : '' ?>
                    <?= !empty($item['title']) ? $item['title']: '' ?>
                </li>
                <?php endforeach; ?>
            </ul>
        </div>
<?php endif; ?>

<?php if (!empty($extraDataTpl)): ?>
        <!--ajax额外数据模板-->
        <?= $this->renderPhpFile($extraDataTpl['tpl'], ['cols' => $extraDataTpl['cols']]) ?>
<?php endif; ?>

        <table class="layui-hide" id="ym2_builder_<?= $id ?>"></table>
        <!--树表格模板 end -->
        <?= /* @var \builder\tree_table\TreeTableBuilder $this->context */ $this->context->endTreeTable() ?>

    </div>

    <!-- 头部工具栏模板 start -->
<?php if (!empty($ttToolbarCustom['left'])): ?>
    <script type="text/html" id="ym2_toolbar_<?= $id ?>">
        <div class="layui-btn-container">
<?php foreach ($ttToolbarCustom['left'] as $item): ?>
            <button class="layui-btn layui-btn-sm px-15 <?= $item['btnClass'] ?>" lay-event="<?= $item['options']['__event_id'] ?>">
<?php if (!empty($item['icon'])): ?>
                <span class="<?= $item['icon'] ?>"></span>
<?php endif; ?>
                <?= $item['title'] ?>
<?php if ($item['options']['type'] == 'dropdown'): ?>
                <i class="layui-icon layui-font-12 layui-icon-down"></i>
<?php endif; ?>
            </button>
<?php endforeach; ?>

        </div>
    </script>
<?php endif; ?>
    <!-- 头部工具栏模板 end -->

    <!--行工具栏模板 start -->
    <script type="text/html" id="ym2_tool_<?= $id ?>">
        <div class="layui-btn-container">
<?php if (!empty($ttRowOperation['normal'])): ?>
<?php foreach ($ttRowOperation['normal'] as $item): ?>
<?php if (!empty($operationId = $item['options']['operationId'])): // ID存在定义 ?>
            {{#  if(d["<?= $operationId ?>"]){ }}
            <button class="layui-btn layui-btn-xs layui-btn-primary f12" lay-event="<?= $item['options']['__event_id'] ?>">
<?php if (!empty($item['options']['icon'])): ?>
                <span class="<?= $item['options']['icon'] ?>"></span>
<?php endif; ?>
                <?= $item['options']['title'] ?>
            </button>
            {{#  } }}
<?php else: // ID未定义 ?>
            <button class="layui-btn layui-btn-xs layui-btn-primary f12" lay-event="<?= $item['options']['__event_id'] ?>">
<?php if (!empty($item['options']['icon'])): ?>
                <span class="<?= $item['options']['icon'] ?>"></span>
<?php endif; ?>
                <?= $item['options']['title'] ?>
            </button>
<?php endif; ?>
<?php endforeach; ?>
<?php endif; ?>

<?php if (!empty($ttRowOperation['more'])): ?>
            <button class="layui-btn layui-btn-xs layui-btn-theme" lay-event="ym2_row_event_group_more">
                更多
                <i class="layui-icon layui-icon-down"></i>
            </button>
<?php endif; ?>
        </div>
    </script>
    <!--行工具栏模板 end -->

    <!-- 分页栏自定义工具项 start -->
<?php if (!empty($ttToolbarCustom['bottom'])): ?>
        <script type="text/html" id="ym2-pagebar_<?= $id ?>">
            <div class="layui-btn-container">
<?php foreach ($ttToolbarCustom['bottom'] as $item): ?>
                <button class="layui-btn layui-btn-sm px-15 <?= $item['btnClass'] ?>" lay-event="<?= $item['options']['__event_id'] ?>">
<?php if (!empty($item['icon'])): ?>
                    <span class="<?= $item['icon'] ?>"></span>
<?php endif; ?>
                    <?= $item['title'] ?>
<?php if ($item['options']['type'] == 'dropdown'): ?>
                    <i class="layui-icon layui-font-12 layui-icon-down"></i>
<?php endif; ?>
                </button>
<?php endforeach; ?>
            </div>
        </script>
<?php endif; ?>
    <!-- 分页栏自定义工具项 end -->

</div>